package com.bmps.springcloud.insuredmicroservice.service.amnt.strategy;

import com.bmps.springcloud.common.utils.DateUtil;
import com.bmps.springcloud.insuredmicroservice.constant.accept.AcceptConstant;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.InsurantModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.ProductModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.RequestModel;
import com.bmps.springcloud.insuredmicroservice.model.trail.TrialPersonModel;
import com.bmps.springcloud.insuredmicroservice.service.RedisService;
import com.bmps.springcloud.insuredmicroservice.util.accept.AcceptUtil;

import java.math.BigDecimal;

public class Lbt036AmntStrategy implements AmntStrategy {
    @Override
    public TrialPersonModel amntTrialCalculation(ProductModel productModel, RequestModel requestModel, RedisService redisService) {
        /**
         * select ? Prem ? / 100 * RATE
         *   from RATE_LBT036
         *  where sex = '?Sex?'
         *    and age = ? AppAge ?
         *    and InsuYear = '?InsuYear?'
         *    保费算保额
         */
        InsurantModel insurantModel = AcceptUtil.getInsurantModelBySeq(productModel.getProdInsSeq(), requestModel.getCustInfo().getInsurants().getInsurant());
        TrialPersonModel trialPersonModel = new TrialPersonModel();
        trialPersonModel.setRiskCode(productModel.getProdCode());
        trialPersonModel.setPrem(productModel.getPrem());
        trialPersonModel.setSex(insurantModel.getSex());
        trialPersonModel.setAppAge(DateUtil.getYears(insurantModel.getBirthday(),requestModel.getPolicyInfo().getPolApplyDate()));
        trialPersonModel.setInsuYear(productModel.getInsureYear());
        trialPersonModel.setComplex(BigDecimal.valueOf(100));
        TrialPersonModel calculateMode = redisService.getCalculateMode(trialPersonModel, AcceptConstant.CALCULATION_TYPE_P);
        return calculateMode;
    }
}
